package com.heima.bos.web.action.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.heima.bos.domain.Decidezone;
import com.heima.bos.service.BaseService;
import com.heima.bos.service.DecidezoneService;
import com.heima.bos.web.action.DecidezoneActionInter;
import com.heima.crm.domain.Customer;
import com.heima.crm.service.CustomerService;
@Controller
@Scope("prototype")
public class DecidezoneAction extends BaseAction<Decidezone> implements DecidezoneActionInter{
	
	@Resource
	private DecidezoneService decidezoneService;
	@Override
	protected BaseService<Decidezone> getService() {
		return decidezoneService;
	}
	private String[] subareaIds;
	public void setSubareaIds(String[] subareaIds) {
		this.subareaIds = subareaIds;
	}
	/**
	 * 重写save方法
	 */
	public String save(){
		decidezoneService.save(entity,subareaIds);
		return "addSuccess";
	}
	/**
	 * 分页查询
	 */
	public String pageQuery(){
		pageList();
		String[] excludes = new String[]{"subareas","decidezones","detachedCriteria","page","pageSize"};
		writePageBean2Json(pageBean, excludes);
		return NONE;
	}
	/**
	 * 通过代理对象查询为关联定区的客户
	 */
	//注入代理客户服务对象
	@Resource
	private CustomerService customerService;
	//未关联客户
	public String findnoassociationCustomers(){
		
		List<Customer> list = customerService.findnoassociationCustomers();
		String[] excludes = new String[]{"station","telephone","address","decidedzone_id"};
		writeList2Json(list, excludes);
		return NONE;
	}
	//已关联客户
	public String findhasassociationCustomers(){
		
		List<Customer> list = customerService.findhasassociationCustomers(entity.getId());
		String[] excludes = new String[]{"station","telephone","address","decidedzone_id"};
		writeList2Json(list, excludes);
		return NONE;
	}
	//注入客户id
	private Integer[] customerIds;
	public void setCustomerIds(Integer[] customerIds) {
		this.customerIds = customerIds;
	}

	//保存关联客户信息
	public String assignCustomersToDecidedZone(){
		customerService.assignCustomersToDecidedZone(customerIds, entity.getId());
		return "addSuccess";
	}
}
